package 笔试记录.M9day22深信服;

public class Main2 {
    public String get_substr (String st) {
        // write code here

        int count = 1;//计数器，统计当前相同字符数量
        for (int i = 1; i < st.length(); i++) {
            if(st.charAt(i) == st.charAt(i - 1)){
                count++;
                //排除一下特殊情况
                if(count >= 3 && i == st.length() - 1){
                    st = st.substring(0,i - 2);
                    count = 0;
                    i = 0;
                }
                continue;
            }
            if(count >= 3) {
                st = st.substring(0, i - count) + st.substring(i);
                i = 0;
            }
            count = 1;
        }
        return st;
    }
}
